" 指示vim-airline使用兼容Powerline的字体符号
let g:airline_powerline_fonts = 1
" 设置渲染字体，需要安装jetbrains nerd font mono, 可以从这里下载https://github.com/ryanoasis/nerd-fonts/releases
set guifont=JetBrainsMono\ Nerd\ Font\ Mono

" 单独给tabline设置分隔符
" 注意使用unicode编号时，要用双引号，表示这个字符串会出现转义字符
let g:airline#extensions#tabline#left_sep = "\uE0C8"
let g:airline#extensions#tabline#left_alt_sep = '>'
let g:airline#extensions#tabline#right_sep = "\uE0B6"
let g:airline#extensions#tabline#right_alt_sep = '<'


" 设置状态栏的分割符号
" 字体符号(比如\uE0C0)的选择，可以参考https://github.com/ryanoasis/powerline-extra-symbols#Glyphs
let g:airline_left_sep = "\uE0C0"
"let g:airline_left_sep = '>'
let g:airline_left_alt_sep = '|'
let g:airline_right_sep = "\uE0C2"
"let g:airline_right_sep = '<'
let g:airline_right_alt_sep = '|'

" 更改分割section的分割符号
let g:airline_section_left_sep = '\uE0B0'
let g:airline_section_left_alt_sep = '|'
let g:airline_section_right_sep = '\uE0B2'
let g:airline_section_right_alt_sep = '|'

" 启动tabline
let g:airline#extensions#tabline#enabled = 1
" airline 在每个tab中不是默认启用的，所以需要显示设置
let g:airline#extensions#tabline#always_show_tabs = 1
" 设置airline主题，参考https://github.com/vim-airline/vim-airline-themes

" 支持哪些主题，可以参考https://github.com/vim-airline/vim-airline/wiki/Screenshots
let g:airline_theme='violet'
" 显示tabline
set showtabline=2
" 设置状态栏和tab设置
set laststatus=2

" 在启动时，打开每个缓冲区到每个tab
function! SetBufferTab()
    let buffers = range(1, bufnr('$'))
    for buf in buffers
        " 如果缓冲区没有窗口
        if bufwinnr(buf) == -1
            execute 'tabnew' bufname(buf)
        endif
    endfor
endfunction

" 进入vim后，会默认打开缓冲区
autocmd VimEnter * call SetBufferTab()

" 当你进入一个新的tab时，会默认打开一个新的airline
autocmd TabEnter * call airline#update_statusline()
" 当你使用tl和th切换缓冲区和tab时，默认情况下是不会重新打开airline的
" 所以就需要我们重新设置tl和th，让他们在切换完tab后再次打开airline
function! SwitchTab(direction)
    if a:direction == 'next'
        tabnext
    elseif a:direction == 'prev'
        tabprevious
    endif

    call airline#update_statusline()
endfunction

" 取消tl和th的绑定
nunmap tl
nunmap th
" 重新声明
nnoremap tl :call SwitchTab('next')<CR>
nnoremap th :call SwitchTab('prev')<CR>
